package com.example.myandroidtest.ui.retrofit;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myandroidtest.bean.Column;
import com.example.myandroidtest.common.http.HttpUtils;
import com.example.myandroidtest.common.http.Subscriber;
import com.example.myandroidtest.databinding.ActivityRetrofitBinding;

import java.util.List;

public class RetrofitActivity extends AppCompatActivity {

    ActivityRetrofitBinding binding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityRetrofitBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());

        initView();
    }

    private void initView() {
        binding.toolbar.ivBack.setOnClickListener(v -> finish());
        binding.toolbar.tvTitle.setText("网络请求");

        binding.btnRequest.setOnClickListener(v -> {
            request();
        });
    }


    public void request() {
        HttpUtils.toSubscribe(HttpUtils.getApi().getColumnList(0, 95),
                new Subscriber<List<Column>>() {
                    @Override
                    public void onNext(List<Column> value) {
                        binding.tvResponse.setText(value.toString());
                    }

                    @Override
                    public void onError(Throwable e) {

                    }
                });
    }
}